// 数据库操作
const mongoose = require('mongoose');
// 模型规则类
const { Schema } = mongoose;

// 用户集合规则
const incAndExpSchema = new Schema({
    /* 用户名 */
    username: {
        type: String,
        required: true,
        maxlength: 30
    },
    /* 用户手机号 */
    phone: {
        type: String,
        required: true,
        maxlength: 11
    },
    // 名称
    name: {
        type: String,
        required: true,
        maxlength: 11
    },
    // 标签
    //0 是支出，1是收入
    label: {
        type: Number,
        required: true,
        default: 0,
    },
    // 分类
    type: {
        type: Object,
        required: true,
    },
    // 金额
    price: {
        type: String,
        required: true,
        maxlength: 11
    },
    //预算
    budget: {
        type: String,
        maxlength: 11
    },
    //余额
    balance: {
        type: String,
        maxlength: 11
    },
    // 创建时间
    createTime: {
        type: Number,  //时间戳必须用Number数据类型
        required: true,
    },
    // 备注信息
    notes: {
        type: String,
        maxlength: 100
    }

}, { versionKey: false });

// 用户集合类
const IncAndExp = mongoose.model('incAndExp', incAndExpSchema);

create();

// 创建集合
async function create() {
    // 初始化用户
    const inc = await IncAndExp.create({
        username: '肖芬芳',
        phone: '13212774009',
        name: '购买早餐',
        label: 0,
        type: { value: '12321', label: '饮食' },
        price: '5',
        budget: '500',
        balance: '',
        notes: '热干面',
        createTime: new Date().getTime()
    });
}


module.exports = {
    IncAndExp
}